from tortoise import fields, models


class Role(models.Model):
    """"角色表"""
    id = fields.IntField(pk=True, description="角色ID")
    code = fields.CharField(max_length=20, unique=True, description="角色编码", index=True)
    name = fields.CharField(max_length=20, unique=True, description="角色名称", index=True)
    desc = fields.CharField(max_length=500, null=True, description="角色描述")
    # menus = fields.ManyToManyField("models.Menu", related_name="role_menus")
    # apis = fields.ManyToManyField("models.Api", related_name="role_apis")
    created_time = fields.DatetimeField(auto_now_add=True, description='创建时间')
    updated_time = fields.DatetimeField(auto_now=True, description="更新时间")
    deleted_time = fields.DatetimeField(null=True, description="删除时间")
    is_deleted = fields.BooleanField(default=False, description="是否删除")

    class Meta:
        table = "tb_mall_role"
        table_description = "角色表"

    def __repr__(self):
        return f"User(id={self.id}, username={self.name})"

    __str__ = __repr__